package com.response;

import com.enums.ErrorCodeEnum;
import org.springframework.stereotype.Component;

import java.io.Serializable;


@Component
public class BaseRespons<T> implements Serializable {
    private static final long serialVersionUID = 2354881465436907718L;
    private int state = 1;
    private String code = "1";
    private String message = "success";
    private T data;

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public int getState() {
        return state;
    }

    public void setState(int state) {
        this.state = state;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }


    public static BaseRespons success() {
        return new BaseRespons();
    }

    public static BaseRespons success(Object object) {
        BaseRespons<Object> objectBaseRespons = new BaseRespons<Object>();
        objectBaseRespons.setData(object);
        return objectBaseRespons;
    }


    public static BaseRespons error(String code, String mgs) {
        BaseRespons vo = new BaseRespons();
        vo.setCode(code);
        vo.setMessage(mgs);
        vo.setState(0);
        return vo;
    }

    public static BaseRespons error(ErrorCodeEnum errorCodeEnum) {
        BaseRespons vo = new BaseRespons();
        vo.setCode(errorCodeEnum.getCode());
        vo.setMessage(errorCodeEnum.getMessage());
        vo.setState(0);
        return vo;
    }

    public static BaseRespons ok(String code, String mgs) {
        BaseRespons vo = new BaseRespons();
        vo.setCode(code);
        vo.setMessage(mgs);
        return vo;
    }

}
